package com.lagou.cl.redislagouindex.service.impl;

import com.alibaba.fastjson.JSON;
import com.lagou.cl.redislagouindex.cache.LocalCache;
import com.lagou.cl.redislagouindex.pojo.Position;
import com.lagou.cl.redislagouindex.service.PositionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author 程  林
 * @date 2020-09-20 15:02
 * @description //
 * @since V1.0.0
 */
@Service
@Slf4j
public class PositionServiceImpl implements PositionService {

	@Autowired
	private LocalCache localCache;


	/**
	 * 先读本地缓存，本地缓存没有则读分布式缓存，分布式缓存没有则读数据库
	 */

	@Override
	public List<Position> queryPositionByAll() {
		// 所有数据
		String key = "all";
		String data = localCache.getData(key);
		return JSON.parseArray(data, Position.class);
	}

	@Override
	public List<Position> queryPositionByName(String name) {
		// 职位名称
		String key = "name:" + name;
		String data = localCache.getData(key);
		return JSON.parseArray(data, Position.class);
	}


}
